package com.test.springboot.springBootUtils.conf;

import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;

/**
 * Spring命令行开发
 * @author huyong
 *
 */
@ShellComponent
public class TranslationCommands {
	/**
	 * 使用SpringBoot
	 * @author huyong
	 * @date 2020年9月2日下午4:06:27
	 * @return void
	 * 如果 @ShellMethod 不写参数 默认的执行命令是 test-Shell
	 * group: 设置命令的分组
	 * key:设置命令的名称
	 * value:设置命令的描述
	 * prefix: 设置命令的前缀 默认是 --
	 * 该方法的执行语句 print -str huyong 
	 */
	@ShellMethod(group = "test", key = "print", prefix = "-", value = "简单打印命令")
	public void testShell(String str) {
		System.out.println("这里是hello 的字符串" + str);
	}

	@ShellMethod(group = "test", key = "args", prefix = "-", value = "测试参数")
	public void add(@ShellOption(defaultValue = "4", help = "被加数", arity = 3) int[] numbers) {
		int sum = 0;
		for (int number : numbers) {
			sum += number;
		}
		System.out.println(String.format("sum=%d", sum));
	}

}
